package com.myjob.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shopgoods.common.log.annotation.Log;
import com.shopgoods.common.log.enums.BusinessType;
import com.shopgoods.common.security.annotation.RequiresPermissions;
import com.myjob.system.domain.SgAttributes;
import com.myjob.system.service.ISgAttributesService;
import com.shopgoods.common.core.web.controller.BaseController;
import com.shopgoods.common.core.web.domain.AjaxResult;
import com.shopgoods.common.core.utils.poi.ExcelUtil;
import com.shopgoods.common.core.web.page.TableDataInfo;

/**
 * 属性Controller
 * 
 * @author shopgoods
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/attributes")
public class SgAttributesController extends BaseController
{
    @Autowired
    private ISgAttributesService sgAttributesService;

    /**
     * 查询属性列表
     */
    @RequiresPermissions("system:attributes:list")
    @GetMapping("/list")
    public TableDataInfo list(SgAttributes sgAttributes)
    {
        startPage();
        List<SgAttributes> list = sgAttributesService.selectSgAttributesList(sgAttributes);
        return getDataTable(list);
    }

    /**
     * 导出属性列表
     */
    @RequiresPermissions("system:attributes:export")
    @Log(title = "属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SgAttributes sgAttributes)
    {
        List<SgAttributes> list = sgAttributesService.selectSgAttributesList(sgAttributes);
        ExcelUtil<SgAttributes> util = new ExcelUtil<SgAttributes>(SgAttributes.class);
        util.exportExcel(response, list, "属性数据");
    }

    /**
     * 获取属性详细信息
     */
    @RequiresPermissions("system:attributes:query")
    @GetMapping(value = "/{aid}")
    public AjaxResult getInfo(@PathVariable("aid") Long aid)
    {
        return success(sgAttributesService.selectSgAttributesByAid(aid));
    }

    /**
     * 新增属性
     */
    @RequiresPermissions("system:attributes:add")
    @Log(title = "属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SgAttributes sgAttributes)
    {
        return toAjax(sgAttributesService.insertSgAttributes(sgAttributes));
    }

    /**
     * 修改属性
     */
    @RequiresPermissions("system:attributes:edit")
    @Log(title = "属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SgAttributes sgAttributes)
    {
        return toAjax(sgAttributesService.updateSgAttributes(sgAttributes));
    }

    /**
     * 删除属性
     */
    @RequiresPermissions("system:attributes:remove")
    @Log(title = "属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aids}")
    public AjaxResult remove(@PathVariable Long[] aids)
    {
        return toAjax(sgAttributesService.deleteSgAttributesByAids(aids));
    }
}
